<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自动跳转首页</title>
    <style>
        p{
            text-align: center;
        }
        span{
            color: crimson;
        }
    </style>
</head>
<script>
    /**
     *
     */

</script>
<body>
<p>
                再过<span id="time"> 5 </span>秒就要访问百度啦
</p>
<script>
    var num = 5;

    function over() {


    num--;
    if (num<=0){
        location.href="http://baidu.com";
    }
    // var time1 = document.getElementById("time")// 获取这部分可以放在外面，不然执行一次获取一次
        time1.innerHTML=num;


    }

    setInterval(over,1000)
</script>
</body>
</html>